﻿@model WorldArtPrice.Models.PriceSearchResultModel
@{
    ViewBag.Title = "Index";
}
@Scripts.Render("~/Scripts/Jscalendar/calendar.js")
@Scripts.Render("~/Scripts/Jscalendar/calendar-setup.js")
@Scripts.Render("~/Scripts/Jscalendar/lang/calendar-en.js")    
@Styles.Render("~/Scripts/Jscalendar/calendar-win2k-cold-1.css")
<script>
    function ShowAdvance() {
        $('#divAdvanceSearch').show();
    }
    function HideAdvance() {
        $('#divAdvanceSearch').hide();
    }
    $(document).ready(function () {
        //khoi tao calendar
        Calendar.setup({
            inputField: "FromDate",
            button: "f_btn1",
            align: "Tr",
            ifFormat: "%Y/%m/%d"
        });
        Calendar.setup({
            inputField: "ToDate",
            button: "f_btn2",
            align: "Tr",
            ifFormat: "%Y/%m/%d"
        });
    });
</script>
@using (Html.BeginForm("Index", "Price", FormMethod.Post))
{
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true)     
<div id="results">
    <div class="results-controls" id="results-controls-1">
        <div id="results_filters">                                                                
            <div style="float: left; margin-top: 5px;">
                @(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month).ToUpper() +" "+ DateTime.Now.Year)
            </div>
            <div style="float: right;">  
                               
                    @Html.LabelFor(m => m.Title1, new { @class="results_filters_label"})
                    @Html.TextBoxFor(m => m.Title1, new { @class="text placeholder", @Value = Model.KeyWord})
                    <input value="" name="searchSubmit" class="headerSearchSubmit" id="headerSearchSubmit" type="submit">
                    <a href="javascript:ShowAdvance()" style="font-size:16px">Advance Search</a>                
            </div> 
        </div>
        <div class="clearer">
        </div>
        <div class="results-range" style="display:none;border: 1px solid rgb(117, 117, 117); margin-top: 10px; margin-left: 10px; width: 659px; margin-bottom: 10px;" id="divAdvanceSearch" >
                                     
                    <table width="100%" cellspacing="0" cellpadding="0" border="0" id="table5">    
                        <tr>
                            <td valign="top" align="left">                        
                                <h4 style="margin-bottom: 10px;font-size:16px">
                                    Enter what you see:<br>                            
                                    Enter all or part of an artist’s name in the search field. You can use wildcards
                                    if you are in doubt about the spelling.
                                </h4> 
                                <p style="margin-top: 0px; margin-bottom: 10px; padding-left: 0px;">                       
                                    &nbsp;&nbsp;&nbsp; ‘+’ replaces a single letter&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;
                                    ‘*’ replaces several letters
                                <br />
                                    &nbsp;&nbsp;&nbsp; You can enter the auctionTime and/or country for a more refined search.  
                                </p>         
                                <table width="100%" cellspacing="0" cellpadding="5" border="0" id="table6">
                                    <tr>
                                        <td width="25%"><b style="font-size:16px">@Html.LabelFor(m=>m.Title2)</b></td>
                                        <td width="75%">
                                            @Html.TextBoxFor(m=>m.Title2)                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><b style="font-size:16px">@Html.LabelFor(m=>m.FromDate)</b>
                                        </td>
                                        <td>
                                            @Html.TextBoxFor(m => m.FromDate, new { @maxlength="10", @size="10", @value="" })
                                            &nbsp; (date, e.g. 1825-12-24)                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><b style="font-size:16px">@Html.LabelFor(m=>m.ToDate)</b>
                                        </td>
                                        <td>
                                            @Html.TextBoxFor(m => m.ToDate, new { @maxlength="10", @size="10", @value="" })
                                            &nbsp; (date, e.g. 1825-12-24)                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><b style="font-size:16px">@Html.LabelFor(m=>m.CountryId)</b></td>
                                        <td>
                                            @Html.DropDownListFor(m => m.CountryId, new SelectList(Model.ListCoutry, "Id", "Country"))
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><b style="font-size:16px">@Html.LabelFor(m=>m.ItemTypeId)</b></td>
                                        <td>
                                            @Html.DropDownListFor(m => m.ItemTypeId, new SelectList(Model.ListItemType, "Id", "Name"))
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>
                                            <br>                                        
                                            <input type="submit" value="Search" id="send" class="knap" onmouseout="co(this,'out');" onmouseover="co(this,'in');" name="Action">
                                            &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:HideAdvance()" style="font-size:16px">Close</a>
                                        </td>
                                    </tr>
                                </table>            
                            </td>
                        </tr>
                    </table>
                              
            </div>
        @Html.ValidationMessage("Title", new { style="color:#CC0000"})        
        @Html.ValidationMessage("AuctionTime", new { style="color:#CC0000"})         
        <div class="clearer">
        </div>                            
        <div class="results-range">  
            <b>Find price </b>@(!string.IsNullOrEmpty(Model.KeyWord)? '"'+ Model.KeyWord +'"':"")<br />          
            @Model.TotalRecord prices found
        </div>
        <div class="clearer">
        </div>    
    </div>
    <!-- #results-controls-1 -->
    <div class="clearer">
    </div>
    <ul id="list-items">
        @foreach(var item in Model.ListPrices)
        {
            
            BusinessLayer.WorldArtPrice.Entities.ArtWork artWork = new BusinessLayer.WorldArtPrice.ArtWorkBL().GetByPriceId(item.ID).FirstOrDefault();
            BusinessLayer.WorldArtPrice.Entities.Artist artist = new BusinessLayer.WorldArtPrice.ArtistBL().GetArtistById(item.ArtistId);
            BusinessLayer.WorldArtPrice.Entities.AuctionHouse auctionHouse = new BusinessLayer.WorldArtPrice.AuctionHouseBL().GetById(item.AuctionHouse);
            BusinessLayer.WorldArtPrice.Entities.AuctionHouseSublocation auctionHouseSublocation = new BusinessLayer.WorldArtPrice.AuctionHouseSublocationBL().GetById(item.AuctionHouseSublocation);
            BusinessLayer.WorldArtPrice.Entities.ItemType itemType = new BusinessLayer.WorldArtPrice.ItemTypeBL().GetById(item.ItemType);
            BusinessLayer.WorldArtPrice.Entities.Currencys estimatedCurrency = new BusinessLayer.WorldArtPrice.CurrencyBL().GetById(item.EstimatedCurrency);
            BusinessLayer.WorldArtPrice.Entities.Currencys priceCurrency = new BusinessLayer.WorldArtPrice.CurrencyBL().GetById(item.PriceCurrency);
            string action = string.Empty;
            
            <li class="" id="day-19">
                <div class="auction-date" style="background:none; width:160px">
                    <ul style="padding-left: 0px;">
                    @{                        
                        if(artWork!=null)
                        {
                            string urlImage = CommandLib.Config.UrlImage + CommandLib.Parameter.IMAGE_ARTWORK + "/" + artWork.ArtworkId + "/" + artWork.ArtworkFile.Substring(artWork.ArtworkFile.LastIndexOf("/") + 1);
						    <li style="border:none !important; text-align: center;">
                                <a href="#"><img src="@urlImage" data-large="@urlImage" style="max-width:150px"/></a>
						    </li>			
                        }						            
                        else
                        {
                            <li style="border:none !important; text-align: center;">
                                <a href="#"><img src="/Content/Images/default.png"  style="max-width:150px;max-height:180px" /></a>
                            </li>
                        }
                    }
                    </ul>
                </div>
                <div class="auction-info" style="border-left: none !important;">
                    <div class="clearer"></div>
                    <ul class="auction-links">
                        <li>
                            @{
                                if(artist!=null)
                                {
                                    <span> 
                                        @{action = "GetByArtist/1/" + @artist.ArtistId + "/" + @CommandLib.Utils.UnicodeToKoDauAndGach(HttpUtility.HtmlDecode(artist.FullName)) + ".html";}                   
                                        @Html.ActionLink(HttpUtility.HtmlDecode(string.IsNullOrEmpty(artist.FullName) ? "Unknown" : artist.FullName), action, "Price", null) 
                                        @((artist.Born == 0 ? "Born unknown" : artist.Born.ToString()) + " - " + (artist.Died == 0 ? "Die unknown" : artist.Died.ToString()))
                                    </span>
                                }    
                            }
                        </li>
                    </ul>                                
                        @{action = "Detail/" + @item.ID + "/" + @CommandLib.Utils.UnicodeToKoDauAndGach(HttpUtility.HtmlDecode(item.ItemName)) + ".html";}           
                        @Html.ActionLink(HttpUtility.HtmlDecode(item.ItemName), action, "Price", null, new { @class = "description" })                                       
                    <table>
                        <tr valign="top">
                            <td width="50%">
                                <b style="text-transform:uppercase;">Category:</b> @(itemType !=null ? itemType.Name : "")
                            </td>
                            <td style="padding-left: 20px;">
                                <b>Auction House:</b> 
                                @{
                                    if(auctionHouse != null)
                                    {
                                        <a href="@auctionHouse.Link" target="_blank">@(auctionHouse.Name)</a>
                                    }    
                                }                                
                            </td>
                        </tr>
                        <tr valign="top">
                            <td>
                                <b style="text-transform:uppercase;">Dimension:</b> @item.Width x @item.Height @item.Measurement
                            </td>
                            <td style="padding-left: 20px;">
                                <b>Auction:</b> 
                                @System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.AuctionTime.Month).Substring(0,3).ToUpper() @item.AuctionTime.Day, @item.AuctionTime.Year                                
                            </td>
                        </tr>
                        <tr valign="top">
                            <td>
                                <b style="text-transform:uppercase;">Estimated price:</b> @(CommandLib.Utils.ConvertMoney(item.EstimatedFrom.ToString())) -  @(CommandLib.Utils.ConvertMoney(item.EstimatedTo.ToString())) @estimatedCurrency.Currency
                            </td>
                            <td style="padding-left: 20px;">
                                <b>Place:</b> 
                                @(auctionHouseSublocation != null ? auctionHouseSublocation.Name : string.Empty)                                
                            </td>
                        </tr>
                        <tr valign="top">
                            <td>
                                <b style="text-transform:uppercase;">Price:</b> @(item.Unsold ? " Unsold" : CommandLib.Utils.ConvertMoney(item.Price.ToString()) + " "+ priceCurrency.Currency)
                            </td> 
                            <td style="padding-left: 20px;">
                                <b>Lot number:</b> 
                                @item.Lotnumber
                            </td>
                        </tr>                       
                    </table>
                </div>
                <div class="clearer"></div>
            </li>
        }
    </ul>
    <div class="results-nav" id="results-nav">                
        <div id="divPager" style="width: 100% !important; min-height: 0px !important; text-align: center; margin-left: 0px;">   
            <span style="float:left">
            Results
            @((Model.PageIndex - 1) * 30 + 1)
            &nbsp;-&nbsp;
            @((Model.PageIndex * 30) < Model.TotalRecord ? (Model.PageIndex * 30) : Model.TotalRecord)
            &nbsp;of&nbsp;@Model.TotalRecord
            </span>
            <span style="text-align:center">                                 
                @{                                        
        int totalPage = Convert.ToInt32(Model.TotalRecord) % 30 == 0 ? Convert.ToInt32(Model.TotalRecord) / 30 : (Convert.ToInt32(Model.TotalRecord) / 30) + 1;
        int pageIndex = Convert.ToInt32(Model.PageIndex);
                }
                @if (totalPage > 1)
                {
                    if (pageIndex > 1)
                    {                      
                        @Html.ActionLink("<<", "Index", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = 1 }, new { style = "margin-left:10px;color:#6C6C6C; text-decoration: none;" })
                        @Html.ActionLink("<", "Search", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = pageIndex - 1 }, new { style = "margin-left:10px;color:#6C6C6C; text-decoration: none;" }) 
                    }
                    var startPoint = (totalPage < 15) ? 1 : ((pageIndex > 14) ? pageIndex - 13 : 1);
                    var endPoint = (totalPage < 15) ? totalPage : ((pageIndex > 14) ? pageIndex : 14);
                    for (var page = startPoint; page <= endPoint; page++)
                    {
                        if (page == pageIndex)
                        {                                                                
                            @Html.ActionLink(page.ToString(), "Index", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = page }, new { style = "color: #000000;margin-left:10px;" }) 
                        }
                        else
                        {                                                                
                            @Html.ActionLink(page.ToString(), "Index", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = page }, new { style = "margin-left:10px;color:#6C6C6C; text-decoration: none;" })
                        }
                    }
                    if (pageIndex < totalPage)
                    {                                                                                                            
                        @Html.ActionLink(">", "Index", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = pageIndex + 1 }, new { style = "margin-left:10px;color:#6C6C6C; text-decoration: none;" })
                        @Html.ActionLink(">>", "Index", "Price", new { keyword = Server.UrlEncode(Model.KeyWord), fromDate = Model.FromDate, toDate = Model.ToDate, country = Model.CountryId, category = Model.ItemTypeId, pageIndex = totalPage }, new { style = "margin-left:10px;color:#6C6C6C; text-decoration: none;" })
                    }
                }     
            </span>   
        </div>
    </div>
    <div class="clearer">
    </div>
    <!-- #results-controls-2 -->
    <div class="bottom-note">
        If you do not find the specific auction results you are interested in, please call
        our automated service at +1 212 703 8080 (New York) or +44 (0)20 7627 2707 (London).
    </div>
    <br>
</div>
}

